import {router} from './index';
import {useUserStore} from '../pinia/user'
import { useControlStore } from '../pinia/loginController'

router.beforeEach((to,from,next)=>{
    const store1 =useUserStore()
   const store2 = useControlStore()
    if(!store1.getToken){
        if(to.matched.length>0 && !to.matched.some(item=>item.meta.required)){
            next()
        }else{
            next('/login')
        }
    }else{
        if(!store2.permissionList){
            store2.FETCH_PERMISSION().then(res=>{    
                next({path:to.path})
            })
        }else{
            if(to.path !== '/login'){
                next()
            }else{
                next(from.fullPath)
            }
        }
    }

   

})


